function UTIL_RemoveAllChildren(obj) {
  for (var i = obj.childNodes.length - 1; i >= 0; --i) {
    obj.removeChild(obj.childNodes[i]);
  }
}

function UTIL_GetBits(half_byte, list) {
  for (var i = 8; i != 0; i = parseInt(i/2)) {
    if (half_byte >= i) {
      list.push(1);
      half_byte -= i;
    } else {
      list.push(0);
    }
  }
}

function UTIL_GetBlackWhiteCanvasUsingULongStr(code) {
  var zo = [];
  for (var i = 0; i < code.length; ++i) {
    var x = parseInt(code.charAt(i), 16);  // Not code.charCodeAt
    UTIL_GetBits(x, zo);
  }

  var size = 8;
  var scale = 8;
  var c = document.createElement('canvas');
  c.width = size * scale;
  c.height = size * scale;

  var ctx = c.getContext("2d");
  var d = ctx.createImageData(c.width, c.height);

  var k = 0;
  for (var i = 0; i < size; ++i) {
    for (var j = 0; j < size; ++j) {
      var rgb = 255 * zo[k];

      for (var x = i * scale; x < (i + 1) * scale; ++x) {
        for (var y = j * scale; y < (j + 1) * scale; ++y) {
          var id = (x * c.width + y) * 4;
          d.data[id] = d.data[id + 1] = d.data[id + 2] = rgb;
          d.data[id + 3] = 255;
        }
      }

      ++k;
    }
  }

  ctx.putImageData(d, 0, 0);
  return c;
}

